<div class="ajax_login">
    <div class="title">
        <div class="logo">{:C('qscms_site_name')}&nbsp;&middot;&nbsp;登录</div>
        <div class="close J_btncancel"></div>
    </div>
    <div class="lmain">
        <div class="frombox">
            <div class="tab">
                <if condition="C('qscms_sms_open') eq 1"><div class="li select J_switch" data="J_type1">手机动态码登录</div></if>
                <div class="li <if condition="C('qscms_sms_open') neq 1">select</if> J_switch" data="J_type2">用户名登录</div>
                <div class="clear"></div>
            </div>
            <if condition="C('qscms_sms_open') eq 1">
            <div class="login_type J_type1" style="display:block">
                <form action="" id="topLoginFormMobile" method="get">
                    <div class="ce">
                        <div class="imgbg"></div>
                        <input name="mobile" id="mobile" type="text" maxlength="11" class="linput" placeholder="请输入手机号" autocomplete="off"/>
                        <div class="send_code" id="topGetCodeBtn">获取验证码</div>
                    </div>
                    <div class="ce">
                        <div class="imgbg pwd"></div>
                        <input name="verfy_code" id="verfy_code" type="text" value="" class="linput pwd" placeholder="请输入验证码" autocomplete="off"/>
                    </div>
                    <div class="err"><!--错误提示 --></div>
                    <div class="ce">
                        <input class="btn" type="button" name="submit" id="topLoginBtnMobile" value="登录" />
                    </div>
                    <div class="ce">
                        <div class="imgchecked_txt expLoginBtn"><input name="expire" type="hidden" value="0" />自动登录</div>
                        <div class="getpwd link_gray3"><a href="{:U('members/user_getpass')}">忘记密码?</a></div>
                    </div>
                </form>
            </div>
            </if>
            <div class="login_type J_type2" <if condition="C('qscms_sms_open') neq 1">style="display:block"</if>>
                <form action="" id="topLoginForm" method="get">
                    <div class="ce">
                        <div class="imgbg"></div>
                        <input name="username" type="text" maxlength="16" id="username" class="linput" placeholder="请输入用户名/手机号"  autocomplete="off"/>
                    </div>
                    <div class="ce">
                        <div class="imgbg pwd"></div>
                        <input name="password" type="password" id="password" value="" class="linput pwd" placeholder="请输入密码"  autocomplete="off"/>
                    </div>
                    <div class="err"><!--错误提示 --></div>
                    <div class="ce">
                        <input class="btn" type="button" name="submit" id="topLoginBtn" value="登录" />
                    </div>
                    <div class="ce">
                        <div class="imgchecked_txt expLoginBtn"><input name="expire" type="hidden" value="0" />自动登录</div>
                        <div class="getpwd link_gray3"><a href="{:U('members/user_getpass')}">忘记密码?</a></div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="rmain">
        <div class="tit">使用第三方账号登录</div>
        <div class="api_login">
            <volist name="oauth_list" id="oauth">
                <a class="uu_api_login_btn {$key}" href="{:U('callback/index',array('mod'=>$key,'type'=>'login'))}" title="{$oauth.name}账号登录"></a>
            </volist>
            <div class="clear"></div>
        </div>
        <div class="btnbox">
            <div class="btn_green_api btn_inline  btn_border J_top_loging_user_reg">注册账号</div>
        </div>
    </div>
    <div class="clear"></div>
    <input type="button" id="btnTopCheck" style="display:none;">
    <input type="button" id="btnTopLoginMobile" style="display:none;">
    <input type="button" id="btnTopLoginName" style="display:none;">
    <div id="topCaptchaBox"></div>
    <div id="topCaptchaBoxLog"></div>
    <div id="topCaptchaBoxLogMobile"></div>
</div>
<script type="text/javascript">
    $('.J_btncancel').die().live('click', function() {
        $(".modal,.modal_backdrop").remove();
    });
    //切换登录类型
    $(".J_switch").die().live('click', function(){
        $('.frombox .tab .li').removeClass("select");
        $(this).addClass("select");
        $('.login_type').hide();
        data=$(this).attr('data');
        $('.'+data).show();
    });
    //指定到验证码登录
    /*$('.J_select_code').die().live('click', function() {
        $('.frombox .tab .li').removeClass("select");
        $('.frombox .tab .li').eq(1).addClass("select");
        $('.login_type').hide();
        data=$('.frombox .tab .li').eq(1).attr('data');
        $('.'+data).show();
    });*/
    //用户名和密码登录
    $("#topLoginBtn").die().live('click', function(){
        var usernameValue = $.trim($('#topLoginForm #username').val());
        var passwordValue = $.trim($('#topLoginForm #password').val());
        var expireValue = $.trim($('#topLoginForm input[name=expire]').val());
        $("#topLoginForm .err").hide();
        if (usernameValue == '' || passwordValue == ''){
            $("#topLoginForm .err").html('用户名和密码不能为空！').show();
            //disapperTooltip("remind",'用户名和密码不能为空！');
        } else {
            // 判断是否需要出现验证
            if (eval(qscms.varify_user_login) && eval(qscms.captcha_open)) {
                $('.geetest_panel').remove();
                $.ajax({
                    url: qscms.root+'?m=Home&c=captcha&t=' + (new Date()).getTime(),
                    type: "get",
                    dataType: "json",
                    success: function (data) {
                        initGeetest({
                            gt: data.gt,
                            challenge: data.challenge,
                            offline: !data.success,
                            new_captcha: data.new_captcha,
                            product: 'bind'
                        }, function(captchaObj) {
                            captchaObj.appendTo("#topCaptchaBoxLog");
                            captchaObj.onSuccess(function() {
                                var captChaResult = captchaObj.getValidate();
                                var usernameValue = $.trim($('#topLoginForm #username').val());
                                var passwordValue = $.trim($('#topLoginForm #password').val());
                                var expireValue = $.trim($('#topLoginForm input[name=expire]').val());
                                $("#topLoginBtn").val('登录中...').prop("disabled",!0);
                                // 提交表单
                                $.ajax({
                                    url: qscms.root+'?m=Home&c=Members&a=login',
                                    type: "post",
                                    dataType: "json",
                                    data: {
                                        username: usernameValue,
                                        password: passwordValue,
                                        expire: expireValue,
                                        geetest_challenge: captChaResult.geetest_challenge,
                                        geetest_validate: captChaResult.geetest_validate,
                                        geetest_seccode: captChaResult.geetest_seccode
                                    },
                                    success: function (result) {
                                        if (parseInt(result.status)) {
                                            window.location.reload();
                                        } else {
                                            qscms.varify_user_login = result.data;
                                            //disapperTooltip("remind",result.msg);
                                            $("#topLoginForm .err").html(result.msg).show();
                                            $("#topLoginBtn").val('登录').prop("disabled",0);
                                        }
                                    }
                                });
                            });
                            captchaObj.onReady(function () {
                                $("#btnTopLoginName").click();
                            });
                            $('#btnTopLoginName').click(function () {
                                captchaObj.verify();
                            })
                        });
                    },
                    error:function(data){
                        disapperTooltip("remind",data['responseText']);
                    }
                });
            } else {
                doLoginByAccount();
            }
        }
        return false;
    });
    function doLoginByAccount() {
        var usernameValue = $.trim($('#topLoginForm #username').val());
        var passwordValue = $.trim($('#topLoginForm #password').val());
        var expireValue = $.trim($('#topLoginForm input[name=expire]').val());
        $("#topLoginBtn").val('登录中...').prop("disabled",!0);
        // 提交表单
        $.ajax({
            url: qscms.root+'?m=Home&c=Members&a=login',
            type: "post",
            dataType: "json",
            data: {
                username: usernameValue,
                password: passwordValue,
                expire: expireValue
            },
            success: function (result) {
                if (parseInt(result.status)) {
                    window.location.reload();
                } else {
                    qscms.varify_user_login = result.data;
                    //disapperTooltip("remind",result.msg);
                    $("#topLoginForm .err").html(result.msg).show();
                    $("#topLoginBtn").val('登录').prop("disabled",0);
                }
            }
        });
    }
    //手机动态码登录
    var regularMobile = qscms.regularMobile;
    $("#topLoginBtnMobile").die().live('click', function(){
        var mobileValue = $.trim($('#topLoginFormMobile input[name=mobile]').val());
        var verfyCodeValue = $.trim($('#topLoginFormMobile input[name=verfy_code]').val());
        if (mobileValue == "") {
            disapperTooltip("remind", "请输入手机号");
            $('#topLoginFormMobile input[name=mobile]').focus();
            return false;
        }
        if (mobileValue != "" && !regularMobile.test(mobileValue)) {
            disapperTooltip("remind", "手机号码格式不正确");
            $('#topLoginFormMobile input[name=mobile]').focus();
            return false;
        }
        if (verfyCodeValue == "") {
            disapperTooltip("remind", "请填写验证码");
            $('#topLoginFormMobile input[name=verfy_code]').focus();
            return false;
        }
        if (eval(qscms.varify_user_login) && eval(qscms.captcha_open)) {
            $('.geetest_panel').remove();
            $.ajax({
                url: qscms.root+'?m=Home&c=captcha&t=' + (new Date()).getTime(),
                type: "get",
                dataType: "json",
                success: function (data) {
                    initGeetest({
                        gt: data.gt,
                        challenge: data.challenge,
                        offline: !data.success,
                        new_captcha: data.new_captcha,
                        product: 'bind'
                    }, function(captchaObj) {
                        captchaObj.appendTo("#topCaptchaBoxLogMobile");
                        captchaObj.onSuccess(function() {
                            var captChaResult = captchaObj.getValidate();
                            var mobileValue = $.trim($('#topLoginFormMobile input[name=mobile]').val());
                            var verfyCodeValue = $.trim($('#topLoginFormMobile input[name=verfy_code]').val());
                            var expireValue = $.trim($('#topLoginFormMobile input[name=expire]').val());
                            $("#topLoginBtnMobile").val('登录中...').prop("disabled",!0);
                            // 提交表单
                            $.ajax({
                                url: qscms.root+'?m=Home&c=Members&a=login',
                                type: "post",
                                dataType: "json",
                                data: {
                                    mobile: mobileValue,
                                    mobile_vcode: verfyCodeValue,
                                    expire: expireValue,
                                    geetest_challenge: captChaResult.geetest_challenge,
                                    geetest_validate: captChaResult.geetest_validate,
                                    geetest_seccode: captChaResult.geetest_seccode
                                },
                                success: function (result) {
                                    if (parseInt(result.status)) {
                                        window.location.reload();
                                    } else {
                                        qscms.varify_user_login = result.data;
                                        //disapperTooltip("remind",result.msg);
                                        $("#topLoginFormMobile .err").html(result.msg).show();
                                        $("#topLoginBtnMobile").val('登录').prop("disabled",0);
                                    }
                                }
                            });
                        });
                        captchaObj.onReady(function () {
                            $("#btnTopLoginMobile").click();
                        });
                        $('#btnTopLoginMobile').click(function () {
                            captchaObj.verify();
                        })
                    });
                },
                error:function(data){
                    disapperTooltip("remind",data['responseText']);
                }
            });
        } else {
            doLoginByMobile();
        }
    });
    function doLoginByMobile() {
        var mobileValue = $.trim($('#topLoginFormMobile input[name=mobile]').val());
        var verfyCodeValue = $.trim($('#topLoginFormMobile input[name=verfy_code]').val());
        var expireValue = $.trim($('#topLoginFormMobile input[name=expire]').val());
        $("#topLoginBtnMobile").val('登录中...').prop("disabled",!0);
        // 提交表单
        $.ajax({
            url: qscms.root+'?m=Home&c=Members&a=login',
            type: "post",
            dataType: "json",
            data: {
                mobile: mobileValue,
                mobile_vcode: verfyCodeValue,
                expire: expireValue
            },
            success: function (result) {
                if (parseInt(result.status)) {
                    window.location.reload();
                } else {
                    qscms.varify_user_login = result.data;
                    //disapperTooltip("remind",result.msg);
                    $("#topLoginFormMobile .err").html(result.msg).show();
                    $("#topLoginBtnMobile").val('登录').prop("disabled",0);
                }
            }
        });
    }
    //发送验证码
    $("#topGetCodeBtn").die().live('click', function(){
        if ($(this).hasClass('btn_disabled')) {
            return false;
        }
        var mobileValue = $('#topLoginFormMobile input[name="mobile"]').val();
        if (!mobileValue.length) {
            disapperTooltip("remind", "请输入手机号");
            $('#topLoginFormMobile input[name=mobile]').focus();
            return false;
        }
        if (mobileValue != "" && !regularMobile.test(mobileValue)) {
            disapperTooltip("remind", "手机号码格式不正确");
            $('#topLoginFormMobile input[name=mobile]').focus();
            return false;
        }
        $.ajax({
            url: qscms.root + '?m=Home&c=Members&a=ajax_check',
            cache: false,
            async: false,
            type: 'post',
            dataType: 'json',
            data: { type: 'mobile', param: mobileValue },
            success: function(result) {
                if (!result.status) {
                    if (eval(qscms.smsTatus)) {
                        if (eval(qscms.varify_mobile) && eval(qscms.captcha_open)) {
                            $('.geetest_panel').remove();
                            $.ajax({
                                url: qscms.root+'?m=Home&c=captcha&t=' + (new Date()).getTime(),
                                type: "get",
                                dataType: "json",
                                success: function (data) {
                                    initGeetest({
                                        gt: data.gt,
                                        challenge: data.challenge,
                                        offline: !data.success,
                                        new_captcha: data.new_captcha,
                                        product: 'bind'
                                    }, function(captchaObj) {
                                        captchaObj.appendTo("#topCaptchaBox");
                                        captchaObj.onSuccess(function() {
                                            var captChaResult = captchaObj.getValidate();
                                            $('#topGetCodeBtn').text('发送中...').addClass('btn_disabled');
                                            var mobileValue = $.trim($('#topLoginFormMobile input[name=mobile]').val());
                                            $.ajax({
                                                url: qscms.root + '?m=Home&c=Members&a=reg_send_sms',
                                                cache: false,
                                                async: false,
                                                type: 'post',
                                                dataType: 'json',
                                                data: { sms_type: 'login', mobile: mobileValue,geetest_challenge: captChaResult.geetest_challenge,geetest_validate: captChaResult.geetest_validate,geetest_seccode: captChaResult.geetest_seccode},
                                                success: function(result) {
                                                    if (result.status) {
                                                        disapperTooltip("success", "验证码已发送，请注意查收");
                                                        // 开始倒计时
                                                        var countdown = 180;
                                                        function settime() {
                                                            if (countdown == 0) {
                                                                $('#topGetCodeBtn').text('获取验证码').removeClass('btn_disabled');
                                                                countdown = 180;
                                                                return;
                                                            } else {
                                                                $('#topGetCodeBtn').text('重新发送' + countdown + '秒').addClass('btn_disabled');
                                                                countdown--;
                                                            }
                                                            setTimeout(function() {
                                                                settime()
                                                            },1000)
                                                        }
                                                        settime();
                                                    } else {
                                                        $('#topGetCodeBtn').text('获取验证码').removeClass('btn_disabled');
                                                        disapperTooltip("remind", result.msg);
                                                    }
                                                }
                                            });
                                        });
                                        captchaObj.onReady(function () {
                                            $("#btnTopCheck").click();
                                        });
                                        $('#btnTopCheck').click(function () {
                                            captchaObj.verify();
                                        })
                                    });
                                },
                                error:function(data){
                                    disapperTooltip("remind", data['responseText']);
                                }
                            });
                        } else {
                            topSendSms();
                        }
                    } else {
                        disapperTooltip("remind", "短信未开启");
                    }
                } else {
                    disapperTooltip("remind", "账号不存在！");
                }
            }
        });
    });
    // 发送验证码
    function topSendSms() {
        $('#topGetCodeBtn').text('发送中...').addClass('btn_disabled');
        var mobileValue = $.trim($('#topLoginFormMobile input[name=mobile]').val());
        $.ajax({
            url: qscms.root + '?m=Home&c=Members&a=reg_send_sms',
            cache: false,
            async: false,
            type: 'post',
            dataType: 'json',
            data: { sms_type: 'login', mobile: mobileValue},
            success: function(result) {
                if (result.status) {
                    disapperTooltip("success", "验证码已发送，请注意查收");
                    // 开始倒计时
                    var countdown = 180;
                    function settime() {
                        if (countdown == 0) {
                            $('#topGetCodeBtn').text('获取验证码').removeClass('btn_disabled');
                            countdown = 180;
                            return;
                        } else {
                            $('#topGetCodeBtn').text('重新发送' + countdown + '秒').addClass('btn_disabled');
                            countdown--;
                        }
                        setTimeout(function() {
                            settime()
                        },1000)
                    }
                    settime();
                } else {
                    $('#topGetCodeBtn').text('获取验证码').removeClass('btn_disabled');
                    disapperTooltip("remind", result.msg);
                }
            }
        });
    }
    // 自动登录
    $('.expLoginBtn').die().live('click',function() {
        var $chkInp=$(this).find("input");
        var chkInpVal = $chkInp.val();
        if (chkInpVal == '1') {
            $chkInp.val('0');
            $(this).removeClass('select');
        } else {
            $chkInp.val('1');
            $(this).addClass('select');
        }
    });
    // 注册账号
    $('.J_top_loging_user_reg').die().live('click', function () {
        $(".modal,.modal_backdrop").remove();
        siteRegModelShow();
    })
</script>